<!doctype html>
<html>

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
  <link rel="stylesheet" href="../../static/BOSGeo/BOSGeo.css" />
  <title>添加实体</title>
  <style>
    html {
      font-size: 12px;
    }

    html,
    body,
    #mapContainer {
      height: 100%;
      width: 100%;
      padding: 0;
      margin: 0;
    }

  </style>
</head>

<body>
  <div id="mapContainer"></div>
  <div style="position: absolute;left: 20px;top: 20px;">
  <button id="removeentity">从集合中移除实体</button>
    <button id="removecollection">移除集合以及实体</button>
</div>
  <script src="../../static/BOSGeo/BOSGeo.js"></script>
  <script>
    var map = new BOSGeo.Map('mapContainer', {
    mapType: BOSGeo.TDT_IMAGERY
    });

    var layers = map.layers;
    var entityCollection = new BOSGeo.LayerCollection({
        name: '实体集合',
        type: 'entity'
    });

    layers.add(entityCollection);
    var entity = new BOSGeo.EntityLayer({
        name: '实体',
        type: 'polygon', // 实体类型。'line', 'polygon', 'rect', 'ellipse', 'pipeline' 'tube'
        position: [121.46665, 31.17088, 0, 121.4663, 31.16701, 0, 121.46384, 31.1663, 0, 121.46351, 31.16834, 0, 121.46665, 31.17088, 0],
        // width: 6,
        height: 0,
        radius: 20,
        color: '#76f90d',
        attribute: 'aaaa',
        // show: false,
        // opacity: 0.6,
        onClick: layer => {
            // layer.zoomTo();
        }
    });
    entityCollection.add(entity);
    map.flyToEntity(entity.feature, 2);
    // 移除集合上的要素
    document.getElementById('removeentity').addEventListener('click', function () {
        entityCollection.removeAll();
    })
    // 移除图层集合
    document.getElementById('removecollection').addEventListener('click', function () {
        layers.remove(entityCollection);
    })
  </script>
</body>

</html>